feat(json): add reviver support to GET, MGET, and ARRPOP#3205
feat(json): add reviver support to GET, MGET, and ARRPOP#3205JeanSamGirard wants to merge 14 commits into
Conversation
Allows passing an optional JSON.parse reviver function to transformReply. This enables automatic rehydration of types (like Dates) that are not natively supported by JSON. Modified: - JSON.GET: Added reviver to GetOptions - JSON.MGET: Added reviver to arguments - JSON.ARRPOP: Added reviver to ArrPopOptions - generic-transformers: Added reviver to transformRedisJsonReply and transformRedisJsonNullReply arguments Utilized .preserve to pass reviver through commands.
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
|
Hi @JeanSamGirard, thanks for the PR! I’d like 2 changes before merge:
After that, this looks good to merge. P.S. Its generally a good idea to open an issue before any work is done. This way you will make sure the feature is aligned and accepted by the maintainers beforehand, otherwise you are risking investing the time to implement something that could be rejected later. |
Hi, I made the fix for JSON.ARRPOP and added a test using a reviver for the 3 commands. (I'm not sure in which file the test for multi should go) Unfortunately it seems I'm unable to run them on my local for some reason... I'm on Windows 11 with docker desktop I keep getting "before all" hook for "client.json.get" I think the client isn't able to connect to the container. PS: Noted in the future I'll make an issue first ;) PPS: Sorry for all the additional commits, couldn't test locally so I had to trust 😅 |
|
Hi @nkaradzhov, wasn't sure if I should ping in my previous message. I ended up adding the multi() test case in packages\json\lib\commands\GET.spec.ts using multi().json.get for the test. If there's no other changes needed could you please approve so the tests can run? Thank you |
…into feat/json-reviver-support
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit d8f9d88. Configure here.

Allows passing an optional JSON.parse reviver function to transformReply. This enables automatic rehydration of types (like Dates) that are not natively supported by JSON.
Modified:
Utilized .preserve to pass reviver through commands.
Description
I need to store arbitrary data structures in redis that may contain date objects or class instances that need to be rehydrated after being stringified, I believe others may have this need.
Commands that return JSON already needed to go through JSON.parse so this looked like a logical and easy feature to implement with the existing code structure. This is why I went ahead with making a pull request to add this feature myself instead of just creating an issue. (No linked issues)
PS: This is my first time contributing so if I'm doing anything wrong please tell me, thank you.
Checklist
npm testpass with this change (including linting)?Note
Low Risk
Backward-compatible optional API on read paths only; behavior unchanged when reviver is omitted.
Overview
Adds optional
JSON.parsereviver support when decoding JSON command replies, so callers can rehydrate values (e.g. ISO date strings back toDate) after Redis returns plain JSON text.Shared helpers
transformRedisJsonReply/transformRedisJsonNullReplynow take an optionalJsonReviverand pass it intoJSON.parse.JSON.GET,JSON.MGET, andJSON.ARRPOPexposereviveron options (or as a third argument formGet);parseCommandstores it onparser.preserve, which the client already forwards intotransformReply(includingMULTI).ARRPOPoptions typing is tightened so path/index stay grouped with path. JSDoc and integration tests cover reviver behavior andmulti().json.get.Reviewed by Cursor Bugbot for commit 9b35e7f. Bugbot is set up for automated code reviews on this repo. Configure here.